<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="/common/szws.jsp"%>
<%!
	Object sdfeySchedualTime(String doctorId, String deptId, String date, String half){
		Map condition = new HashMap();
		String param = "<Message><RequestInfo>"+"<HospitalID>SDFE</HospitalID><DoctorID>" + doctorId + "</DoctorID><DepartID>" + deptId + "</DepartID><WorkDate>" + date + "</WorkDate><WorkType>" + half + "</WorkType></RequestInfo></Message>";
		condition.put("params", param);
		condition.put("method", "getDtNoInfo");
		String json = HttpUtil.post("http://221.224.34.163:7071/common/web_service.jsp", condition);
		Map result = JSONUtil.fromJson(json,new TypeReference<Map>(){});
		if (result == null)
		    return null;
		return result.get("WorkInfo");
	}
	
	// 附二院
	public String sdfey(Schedule schedule) {
		Message msg = new Message();
		String deptId = schedule.getDeptId();
		String doctorId = schedule.getDoctorId();
		String date = schedule.getDate();
		String half = schedule.getHalf() + "";
		Object obj = sdfeySchedualTime(doctorId, deptId, date, half);
		if (obj == null) {
			return new Message(30041, "没有分时排班").toJson();
		}
		List<Map> arrList = new ArrayList();
		if (obj instanceof Map) 
			arrList.add((Map)obj);
		else 
			arrList = (List<Map>)obj;
		for (Map map:arrList) {
			map.put("left_num", map.remove("LeftNum"));
			map.put("total_num", map.remove("TotalNum"));
			map.put("start_time", map.remove("StartTime"));
			map.put("end_time", map.remove("EndTime"));
			map.put("finished_num", (Tools.getInt(map.get("total_num") + "") - Tools.getInt(map.get("left_num") + "")) + "");
		}
		msg.put("data", arrList);
		return msg.toJson();
	}
	
	// 苏州12320平台
	public String szwjw(Schedule schedule, String hospitalName) {
		String deptName = schedule.getDeptName();
		String expertName = schedule.getDoctorName();
		String date = schedule.getDate();
		String half = schedule.getHalf() + "";
		return schedualTime(hospitalName, deptName, expertName, date, half);
	}
%>
<%
	// 查看排班时间段
	Integer id = input.getInt("id");
	List<Schedule> shcedules = QBuilder.db("basedb").select().from("Schedule").where(new Where("status = ", STATUS_ENABLE).and("id=", id)).query().getResultObj();
	if (shcedules.size() == 0) {
		msg = new Message(30041, "获取号源失败");
		Tools.encryptPrint(out, msg);
		return;
	}
	Schedule schedule = shcedules.get(0);
	hospital = schedule.getHospital();
	String json = msg.toJson();
	if (hospital == 1002)
		json = sdfey(schedule);
	if (hospital == 1010) {
		String hospitalName = "1".equals(schedule.getBranch()+"") ? "苏州市立医院本部" : "2".equals(schedule.getBranch()+"") ? "苏州市立医院东区" : "苏州市立医院北区";
		json = szwjw(schedule, hospitalName);
	}
	Tools.encryptPrint(out, json);
%>